package demo2;

public class Test {
    public static void drawMap1(){
        Cycle cycle=new Cycle();
        Rect rect=new Rect();
        Flower flower=new Flower();
        //这样写有大量的if else
        String []strings={"cycle","rect","rect","cycle","flower"};
        for (String s:strings) {
            if(s.equals("cycle")){
                cycle.draw();
            }
            else if(s.equals("rect")){
                rect.draw();
            }
            else {
                flower.draw();
            }
        }
    }
    public static void drawMap(){
        Cycle cycle=new Cycle();
        Rect rect=new Rect();
        Flower flower=new Flower();
        //引用数组
        Shape[]shapes={cycle,rect,cycle,rect,flower};
        for (Shape shape:shapes){
            shape.draw();
        }
    }
    public static void main(String[] args) {
        drawMap();
    }

}
